package org.aldar.bquest.effects;

import org.aldar.bquest.constants.IConstants;
import org.aldar.bquest.screens.MainBoardScreen;
import org.andengine.entity.Entity;
import org.andengine.entity.IEntity;
import org.andengine.entity.modifier.*;
import org.andengine.util.modifier.IModifier;

import java.util.Random;

/**
 * User: Daria
 * Date: 9/5/14 11:12 PM
 */
public class SymbolAnimationUtil implements IConstants {

    public static void moveSymbolUp(float startX, float startY, final Entity symbol) {
        MainBoardScreen.getScm().getTestLayer().attachChild(symbol);
        symbol.setAlpha(0f);
        symbol.setX(startX);
        symbol.setY(startY);
        float y1 = startY;
        float y2 = y1 + 50;
        float y3 = y2 + 30;
        float y4 = y3 + 30;
        float y5 = y4 + 30;
        float y6 = y5 + 50;
        //symbol.setPosition(CAMERA_WIDTH - 100 + new Random().nextInt(50), 25 + new Random().nextInt(50));
        symbol.registerEntityModifier(new SequenceEntityModifier(
                new DelayModifier(0.01f * new Random().nextInt(50)),
                new ParallelEntityModifier(
                        new AlphaModifier(0.3f, 0, 1),
                        new MoveYModifier(0.3f, y1, y2)),
                new MoveYModifier(0.2f, y2, y3),
                new MoveYModifier(0.2f, y3, y4),
                new MoveYModifier(0.2f, y4, y5),
                new ParallelEntityModifier(
                        new AlphaModifier(0.3f, 1, 0),
                        new MoveYModifier(0.3f, y5, y6, new IEntityModifier.IEntityModifierListener() {
                            @Override
                            public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem) {
                                //To change body of implemented methods use File | Settings | File Templates.
                            }

                            @Override
                            public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) {
                                MainBoardScreen.getInstanceEngine().runOnUpdateThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        symbol.detachSelf();
                                    }
                                });
                            }
                        }))
        ));

    }
}
